package top.healthylife.gateway.platform.anxinsign.basedto;

import lombok.Data;
import lombok.experimental.Accessors;
import top.healthylife.gateway.dto.request.result.ApiResultDto;

@Data
@Accessors(chain = true)
public abstract class TxBaseResponse extends ApiResultDto {
    public static final String DEFAULT_CHARSET = "UTF-8";
    /**
     * base64消息
     */
    protected String base64Message;
    /**
     * 响应签名
     */
    protected String responseSignature;
    /**
     * 响应明文
     */
    protected String responsePlainText;
    /**
     * 响应码
     */
    protected String code;
    /**
     * 响应消息
     */
    protected String message;
    /**
     * 接口码
     */
    protected String txCode;
    /**
     * 加密对象
     */
    protected String dgtlEnvlp;
    protected String signSN;
    protected String encrptSN;

    public TxBaseResponse(){

    }
    //
    //public TxBaseResponse(String responseMessage, String responseSignature) throws Exception {
    //    EncryptAndDecrypt encryptAndDecrypt = EncryptAndDecrypt.getEncryptAndDecrypt();
    //    if (encryptAndDecrypt == null) {
    //        throw new Exception("证书未初始化");
    //    } else {
    //        this.base64Message = responseMessage;
    //        this.responseSignature = responseSignature;
    //        byte[] data = Base64.decode(responseMessage);
    //        this.responsePlainText = new String(data, "UTF-8");
    //        byte[] signature = StringUtil.hex2bytes(responseSignature);
    //        Boolean verify = encryptAndDecrypt.verify(this.responsePlainText.getBytes("UTF-8"), responseSignature);
    //        if (!verify) {
    //            throw new Exception("验证签名失败。");
    //        } else {
    //            String document = this.responsePlainText;
    //            JSONObject jsonObject = JSONObject.parseObject(document);
    //            this.code = jsonObject.getString("Code");
    //            this.message = jsonObject.getString("Message");
    //            this.txCode = jsonObject.getString("TxCode");
    //            this.process(document);
    //        }
    //    }
    //}
    //
    //public TxBaseResponse(String responseMessage, String responseSignature, String responseDgtlEnvlp, String responseSignSN, String responseEncryptSN) throws Exception {
    //    EncryptAndDecrypt encryptAndDecrypt = EncryptAndDecrypt.getEncryptAndDecrypt();
    //    if (encryptAndDecrypt == null) {
    //        throw new Exception("证书未初始化");
    //    } else {
    //        String randomKeyData2 = encryptAndDecrypt.getDecryptKeyByteByRSA(responseDgtlEnvlp);
    //        this.responsePlainText = EncryptAndDecrypt.decodeByAES(randomKeyData2, responseMessage);
    //        Boolean verify = encryptAndDecrypt.verify(this.responsePlainText.getBytes("UTF-8"), responseSignature);
    //        if (!verify) {
    //            throw new Exception("验证签名失败。");
    //        } else {
    //            this.signSN = responseSignSN;
    //            this.encrptSN = responseEncryptSN;
    //            String document = this.responsePlainText;
    //            JSONObject jsonObject = JSONObject.parseObject(document);
    //            this.code = jsonObject.getString("Code");
    //            this.message = jsonObject.getString("Message");
    //            this.txCode = jsonObject.getString("TxCode");
    //            this.process(document);
    //        }
    //    }
    //}

    protected abstract void process(String var1) throws Exception;

}
